import React from 'react'

const posts = [
  "postone",
  "posttwo",
  "postthree"
]
const comments = [
  "commentone",
  "commenttwo",
  "commentthree"
]
class TestSetState extends React.Component {
  constructor (props) {
    super(props)
    this.state = {
      posts: [],
      comments: []
    }
  }

  componentDidMount () {
    this.setState((prevState, props) => {
      return { comments: comments }
    })
  }


  render () {
    return (
      <section>
        <div>
          <span>Posts: </span>
          {
            this.state.posts.map((o, i) => {
              return <p key={i}>{o}</p>
            })
          }
        </div>
        <div>
          <span>Comments: </span>
          {
            this.state.comments.map((o, i) => {
              return <p key={i}>{o}</p>
            })
          }
        </div>
      </section>
    )
  }
}

setTimeout(() => {
  comments[3] = "aaaaa"
  // console.log(comments[3])
}, 1000)

export default TestSetState